#ifndef FILETHREAD_H
#define FILETHREAD_H

#include <QObject>
#include <QThread>
#include <QTcpSocket>
#include <QDebug>
#include <QFile>
#include <QTimer>


class FileThread :public QThread
{
    Q_OBJECT //信号与槽
public:
    explicit FileThread(QTcpSocket *s);
    void run(); //虚函数(线性处理函数)
    bool isSend=false;
    qint64 timeOut=0;
    QString token;
    QList<QString> sendList;

signals:
    void sendToWidget(QByteArray ba);
    void signalSendFile(QString path);

public slots:
    void slotReadFile();
    void slotBytesWritten(qint64 bytes);
    void slotSendFile(QString path);
    void slotFileTimer();

private:
    QTcpSocket *socket;
    /************* Receive file *******************/
    QFile *recvFile;  //要接受的文件
    qint64 totalBytesRead=0;
    qint64 bytesReceived=0;  //已收到数据的大小
    qint64 fileNameSize=0;  //文件名的大小信息
    QByteArray inBlock;   //数据缓冲区
    QString  fileName;  //保存文件路径

    qint64 loadSize=4096;
    qint64 totalBytesWrite=0;
    qint64 bytesToWrite=0;
    QFile *sendFile;
    QByteArray outBlock;

    QTimer *timer;
};

#endif // MYTHREAD_H
